//
//  SettingListViewController.m
//  GYMWinners
//
//  Created by Logic Solutions on 4/14/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "AppDelegate.h"
#import "SettingListViewController.h"
#import "ChangePasswordViewController.h"
#import "ShowLawInfoViewController.h"
#import "ContactUsViewController.h"
#import "ChangePaymentCardViewController.h"
#import "ChangeServerViewController.h"

@interface SettingListViewController ()

@end

@implementation SettingListViewController
@synthesize settingTypes;
@synthesize tableView;

#pragma mark - tableView delegate
- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return [settingTypes count];
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
    return @"设置";
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSLog(@"didSelectRowAtIndexPath:%d",indexPath.row);
    
    if( indexPath.row == 0 )
    {
        NSLog(@"Logout...");
        AppDelegate *appdel = [[UIApplication sharedApplication] delegate];
		UINavigationController* topNController = appdel.tabBarController;        
        [UIView animateWithDuration:0.5 animations:^{topNController.view.alpha = 0.0;} completion:^(BOOL finished) {
            [topNController.view removeFromSuperview];
        }];
    
    }
    else if( indexPath.row == 1 )
    {
        NSLog(@"Change Password...");
        ChangePasswordViewController* summaryViewController=[[ChangePasswordViewController alloc] init];
        [self.navigationController pushViewController:summaryViewController animated:YES];
    }
    else if( indexPath.row == 2 )
    {
        NSLog(@"Change Payment Card...");
        ChangePaymentCardViewController* summaryViewController=[[ChangePaymentCardViewController alloc] init];
        [self.navigationController pushViewController:summaryViewController animated:YES];
    }
    else if( indexPath.row == 3 )
    {
        NSLog(@"Law Info...");
        ShowLawInfoViewController* summaryViewController=[[ShowLawInfoViewController alloc] init];
        [self.navigationController pushViewController:summaryViewController animated:YES];
    }
    else if( indexPath.row == 4 )
    {
        NSLog(@"Contact us...");
        ContactUsViewController* summaryViewController=[[ContactUsViewController alloc] init];
        [self.navigationController pushViewController:summaryViewController animated:YES];
    }
    else if( indexPath.row == 5 )
    {
        NSLog(@"Change IP...");
        ChangeServerViewController* summaryViewController=[[ChangeServerViewController alloc] init];
        [self.navigationController pushViewController:summaryViewController animated:YES];
    }
}

- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString * showTopBoardCellIdentifier = @"ShowSpaceCell"; 
    UITableViewCell* cell=[tableView dequeueReusableCellWithIdentifier:showTopBoardCellIdentifier];
    if(cell==nil){
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:showTopBoardCellIdentifier];        
    }
    cell.textLabel.text=[settingTypes objectAtIndex:indexPath.row];
    cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
    
    return cell;
}



- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];

    settingTypes= [[NSArray alloc] initWithObjects:@"登出",@"修改密码",@"修改信用卡",@"法律条款",@"联系我们", @"修改IP", nil];
    tableView = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame] style:UITableViewStylePlain];  
    tableView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
    
    tableView.delegate=self;
    tableView.dataSource=self;
    tableView.allowsSelection=YES;
    [tableView reloadData];
    
    [self.view addSubview:tableView];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
